<?php

namespace App\Console\Commands;

use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;

class CommandShortRechargeBlack extends Command
{
    protected $signature = 'CommandShortRechargeBlack';

    protected $table = 'recharge_five_minutes_blacklist';
    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '每分钟检查临时充值黑名单是否有超过5分钟的数据,自动更新';


    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    public function handle(){
        do{
            $data = DB::table($this->table)->where('is_delete',0)->get();
            $data = objToArray($data);
            if(empty($data)){
                break;
            }
            foreach($data as $v){
                //时间判断
                $diffMins = Carbon::now()->diffInMinutes($v['log_time']);
                if($diffMins >= 5){
                    DB::table($this->table)->where('id',$v['id'])->update(['is_delete'=>1,'updated_at'=>Carbon::now()->toDateTimeString()]);
                }
            }
        }while(false);
        return true;
    }
}
